clear all; clc; close all;
RC=1e-6;
wmax=1/RC*2*pi*2;
dw=wmax/100;
w=0:dw:wmax;


a=[RC 1];
b=[1];

figure(1)
freqs(b,a,w)
H=freqs(b,a,w);

figure(2)
subplot(2,1,1)
semilogy(w/2/pi/1e6,abs(H)); xlabel('f, MHz'); ylabel('arg(H(f)),deg');
subplot(2,1,2)
plot(w/2/pi/1e6,unwrap(angle(H))); xlabel('f, MHz'); ylabel('|H|');

sys=tf(b,a);
[y,t]=impulse(sys);
figure(3)
plot(t,y); xlabel('t, sec'); ylabel('|H|');


Fs=2*wmax/2/pi;
[bz,az]=bilinear(b,a,Fs);
[Hz,wz]=freqz(bz,az);
figure;
plot(w/2/pi/1e6,abs(H)); xlabel('f, MHz'); ylabel('|H|');

Td=1/Fs;
Tmod=1000*Td;
t=0:Td:Tmod;


stdn=13; n=stdn*randn(1,length(t));
y=filter(bz,az,n);

figure
plot(t,[n;y])
xlabel('t,sec');



nf=fft(n);
yf=fft(y);
mn=sqrt(mean(abs(nf).^2))*2.5;
nf=nf/mn;
yf=yf/mn;
f=0:1/Tmod:(1/Td);
figure;
plot(f/1e6,[abs(nf); abs(yf)],w/2/pi/1e6,abs(H));
xlim([0 Fs/1e6/2]);
xlabel('f, MHz');